home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / actlib10.zip / DATE.H < prev    next >
C/C++ Source or Header  |  1993-01-14  |  3KB  |  125 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)   */
  2.  
  3. #ifndef __Date_H
  4. #define __Date_H
  5.  
  6. #include <time.h>
  7. #include "c2cpp.h"
  8.  
  9.  
  10. /***
  11.  *  Function    :   isleapyear
  12.  *
  13.  *  Description :   Check if given year is leap.
  14.  *
  15.  *  Parameters  :   in   int/unsigned   year
  16.  *
  17.  *  Side-effects:   Macro
  18.  *
  19.  *  Return      :   1 if leap
  20.  *                  2 if not leap
  21.  *
  22.  *  OS/Compiler :   All
  23.  ***/
  24.  
  25. #define isleapyear( year )      ( (! (year % 4) && (year % 100)) || ! (year % 400) )
  26.  
  27.  
  28.  
  29. /***
  30.  *  Function    :   isdatevalid
  31.  *
  32.  *  Description :   Check if given date is valid.
  33.  *
  34.  *  Parameters  :   in   int   day
  35.  *                  in   int   month
  36.  *                  in   int   year
  37.  *
  38.  *  Return      :   1 if valid
  39.  *                  0 if not
  40.  *
  41.  *  OS/Compiler :   All
  42.  ***/
  43.  
  44. EXTERN int isdatevalid( int day, int month, int year );
  45.  
  46.  
  47.  
  48. /***
  49.  *  Function    :   istimevalid
  50.  *
  51.  *  Description :   Check if given time is valid.
  52.  *
  53.  *  Parameters  :   in   int   hour
  54.  *                  in   int   min
  55.  *                  in   int   sec
  56.  *
  57.  *  Return      :   1 if valid
  58.  *                  0 if not
  59.  *
  60.  *  Side-effects:   Macro
  61.  *
  62.  *  OS/Compiler :   All
  63.  ***/
  64.  
  65. #define istimevalid( hour, min, sec ) ( ((hour) >= 0) && ((hour) < 24) && \
  66.                                         ((min)  >= 0) && ((min)  < 60) && \
  67.                                         ((sec)  >= 0) && ((sec)  < 60)    \
  68.                                       )
  69.  
  70.  
  71. /***
  72.  *  Function    :   getdtime
  73.  *
  74.  *  Description :   Get current time and date.
  75.  *
  76.  *  Parameters  :   out  struct tm *dtime  pointer to time & date structure
  77.  *
  78.  *  Return      :   none
  79.  *
  80.  *  OS/Compiler :   ANSI
  81.  ***/
  82.  
  83. EXTERN void getdtime( struct tm *dtime );
  84.  
  85.  
  86.  
  87. /***
  88.  *  Function    :   diffdate
  89.  *
  90.  *  Description :   Compare two dates.
  91.  *
  92.  *  Parameters  :   out  struct tm *dtime  pointer to time & date structure
  93.  *
  94.  *  Decisions   :   No validity checks are made on dates;
  95.  *            if dates are not valid, result is unpredictable.
  96.  *                     
  97.  *  Return      :   Number of days between date1 and date2 (date1 - date2)
  98.  *
  99.  *  OS/Compiler :   ANSI
  100.  ***/
  101.  
  102. EXTERN long diffdate( struct tm dtime1, struct tm dtime2 );
  103.  
  104.  
  105.  
  106. /***
  107.  *  Function    :   day_of_week
  108.  *
  109.  *  Description :   Gives the day of week corresponding to a date
  110.  *
  111.  *  Parameters  :   in   int   day
  112.  *                  in   int   month
  113.  *                  in   int   year
  114.  *
  115.  *  Return      :    0 = sunday, 1 = monday,...
  116.  *                  -1 if date is not valid
  117.  *
  118.  *  OS/Compiler :   ANSI
  119.  ***/
  120.  
  121. EXTERN int day_of_week( int day, int month, int year );
  122.  
  123.  
  124. #endif
  125.